home *** CD-ROM | disk | FTP | other *** search
- ;What it does:
- ;Application Shell
-
- ;Started:
- ;Wed Oct 19, 1988 13:23:44
-
- ;Finished:
- ;Fri Oct 21, 1988 12:06:02
-
- ;By:
- ;John Holder
-
-
- Include Traps.D ; Use System and ToolBox traps
- Include ToolEqu.D ; Use ToolBox equates
- Include SysEqu.D ; Use System equates
- Include FSEqu.D ; Use File equates
-
-
- MACRO SaveRegs =
- MOVEM.L A0-A4/D0-D7,-(SP)
- |
-
- MACRO RestoreRegs =
- MOVEM.L (SP)+,A0-A4/D0-D7
- |
-
-
-
- XREF DoHelp
-
-
- ; Offsets for Event Record:
- what EQU 0 ; Event number
- message EQU 2 ; Additional information
- when EQU 6 ; Time event was posted
- where EQU 10 ; Mouse coordinates
- modify EQU 14 ; State of keys and button
- wWindow EQU 16 ; Find Window's Result
-
- EventMask EQU $0000FFFF
-
- ;menu equates
- AppleMenu EQU 1 ;Apple Menu stuff
- AboutItem EQU 1
- HelpItem equ 2
-
- FileMenu EQU 2 ;File Menu stuff
- QuitItem EQU 1
-
- EditMenu EQU 3 ;Edit Menu stuff
- UndoItem EQU 1
- CutItem EQU 3
- CopyItem EQU 4
- PasteItem EQU 5
- ClearItem EQU 6
-
-
- true equ $0100
- false equ 0
- Nil equ 0
-
- ;About Sample... ALRT ID#
- InfoAlert equ 130
-
-
- ;-----------------------------------------------------------------------------
- ; <<<<< Initialize the managers >>>>>
- ;-----------------------------------------------------------------------------
- PEA -4(A5) ; Quickdraw's global area
- _InitGraf ; Init Quickdraw
- _InitFonts ; Init Font Manager
- MOVE.L #$0000FFFF,D0 ; Flush all events
- _FlushEvents
- _InitWindows ; Init Window Manager
- _InitMenus
- pea Get_Outta_Here ; Quit if bomb!
- _InitDialogs ; Init Dialog Manager
- _TEInit ; Init Text Edit
- _InitCursor ; Turn on arrow cursor
-
- _MoreMasters
- _MoreMasters
-
- bsr SetUpMenus
- bra MainLoop
-
-
- ;-----------------------------------------------------------------------------
- ; <<<<< In case of bomb >>>>>
- ;-----------------------------------------------------------------------------
- Get_Outta_Here
-
- MOVE.W #Nil,-(SP) ;unhilite all menus!
- _HiliteMenu
-
- _ExitToShell
-
-
- ;-----------------------------------------------------------------------------
- ; <<<<< Set up the menus >>>>>
- ;-----------------------------------------------------------------------------
- SetUpMenus
- CLR.L -(SP)
- MOVE.W #AppleMenu,-(SP)
- _GetRMenu
- MOVE.L (SP)+,MenuOneHandle(A5)
-
- MOVE.L MenuOneHandle(A5),-(SP)
- CLR.W -(SP)
- _InsertMenu
-
- MOVE.L MenuOneHandle(A5),-(SP)
- MOVE.L #'DRVR',-(SP)
- _AddResMenu
- CLR.L -(SP)
- MOVE.W #FileMenu,-(SP)
- _GetRMenu
- MOVE.L (SP),MenuTwoHandle(A5)
- CLR.W -(SP)
- _InsertMenu
- CLR.L -(SP)
- MOVE.W #EditMenu,-(SP)
- _GetRMenu
- MOVE.L (SP),MenuThreeHandle(A5)
- CLR.W -(SP)
- _InsertMenu
- _DrawMenuBar
- RTS
-
- ;-----------------------------------------------------------------------------
- ; <<<< Main Event Loop >>>>
- ;-----------------------------------------------------------------------------
- MainLoop
- _SystemTask
- CLR.W -(SP)
- MOVE #EventMask,-(SP) ; Allow 12 low events
- PEA eventRecord(A5) ; Place to return results
- _GetNextEvent ; Look for an event
- MOVE.W (SP)+,D2 ;will be a 1 if application should respond
- BEQ MainLoop ;(not sure about this one, maybe pass something to an accessory)
-
- move eventRecord+what(A5),D0 ;respond
- add D0,D0
- move EventTable(D0),D0
- jmp EventTable(D0) ;jump to appropriate routine
-
- EventTable
- dc MainLoop-EventTable ;null event
- dc MouseDown-EventTable ;mouse down
- dc MainLoop-EventTable ;mouse up
- dc KeyDown-EventTable ;key down
- dc MainLoop-EventTable ;key up
- dc KeyDown-EventTable ;auto key
- dc MainLoop-EventTable ;update event
- dc MainLoop-EventTable ;disk event
- dc MainLoop-EventTable ;activate event
- dc MainLoop-EventTable ;abort
- dc MainLoop-EventTable ;network event
- dc MainLoop-EventTable ;I/O driver event
-
-
-
- ;-----------------------------------------------------------------------------
- ; <<<< Key Down Event >>>>
- ;-----------------------------------------------------------------------------
- KeyDown
- clr.w -(sp)
- pea eventRecord+Modify(A5)
- move.l #7,-(sp)
- _BitTst
- move.w (sp)+,d1
- bne command_down
- bra MainLoop
-
- command_down
- clr.l -(sp)
- move.l eventRecord+message(A5),D1
- move.w D1,-(sp)
- _MenuKey
- move.l (sp)+,D4
- cmp.l #Nil,D4
- beq MainLoop ;not menu choice!
- bra Menu_Key_Jump
-
-
-
- ;-----------------------------------------------------------------------------
- ; <<<< Handle Mouse Down Event >>>>
- ;-----------------------------------------------------------------------------
- MouseDown
- CLR.W -(SP)
- MOVE.L eventRecord+where(A5),-(SP)
- PEA TheWindow(A5) ;returns the window ptr
- _FindWindow
- MOVE.W (SP)+,D0 ;returns where the mouse was
-
- add D0,D0
- move WindowTable(D0),D0
- jmp WindowTable(D0) ;jump to appropriate routine
-
- WindowTable
- dc MainLoop-WindowTable ;In Desk
- dc InMenu-WindowTable ;In Menu Bar
- dc SysWindow-WindowTable ;In System Window
- dc MainLoop-WindowTable ;in Content
- dc MainLoop-WindowTable ;in drag
- dc MainLoop-WindowTable ;in grow
- dc MainLoop-WindowTable ;in go away
-
-
-
- ;-----------------------------------------------------------------------------
- ; <<<< Click in Menu >>>>
- ;-----------------------------------------------------------------------------
- InMenu
- CLR.L -(SP)
- MOVE.L eventRecord+where(A5),-(SP)
- _MenuSelect
- MOVE.L (SP)+,D4
- CMP.L #Nil,D4
- BEQ MainLoop ;no item selected, go to main loop
-
- Menu_Key_Jump
- MOVE.L D4,D6 ;.W of D6 will now have the item #
- SWAP D4 ;Put hi-word into low word of D4
-
- WhichMenuWasIt
- CMP.W #AppleMenu,D4
- BEQ InAppleMenu
- CMP.W #FileMenu,D4
- BEQ InFileMenu
- CMP.W #EditMenu,D4
- BEQ InEditMenu
- BRA MainLoop
-
-
- ;-----------------------------------------------------------------------------
- ; <<<< Where all menu routines end their journey >>>>
- ;-----------------------------------------------------------------------------
- MenuDone
- MOVE.W #Nil,-(SP) ;unhilite all menus!
- _HiliteMenu
- bra MainLoop
-
-
-
- ;-----------------------------------------------------------------------------
- ; <<<< In Apple Menu >>>>
- ;-----------------------------------------------------------------------------
- InAppleMenu
- CMP.W #AboutItem,D6
- BEQ DoAbout
- cmp #HelpItem,D6
- beq DoTheHelp
- Bra DoDeskAcc
- BRA MainLoop
-
-
- ;-----------------------------------------------------------------------------
- ; <<<< Do About... >>>>
- ;-----------------------------------------------------------------------------
- DoAbout
- bsr SaveResFileandPort
- move thisresfile(A5),-(sp)
- _UseResFile
- CLR.W -(SP)
- MOVE.W #InfoAlert,-(SP)
- CLR.L -(SP)
- _Alert
- MOVE.W (SP)+,D0
- bsr RestoreResFileandPort
- BRA MenuDone
-
-
-
- ;-----------------------------------------------------------------------------
- ; <<<< Do Help... >>>>
- ;-----------------------------------------------------------------------------
- DoTheHelp
- bsr DoHelp
- bra MenuDone
-
-
-
- ;-----------------------------------------------------------------------------
- ; <<<< Do a Desk Accessory >>>>
- ;-----------------------------------------------------------------------------
- DoDeskAcc
- bsr saveresfileandport
-
- MOVE.L MenuOneHandle(A5),-(SP)
- MOVE.W D6,-(SP)
- PEA AccName(A5)
- _GetItem
-
- CLR.W -(SP)
- PEA AccName(A5)
- _OpenDeskAcc
- MOVE.W (SP)+,D7
-
- bsr restoreresfileandport
- BRA MenuDone
-
-
-
- ;-----------------------------------------------------------------------------
- ; <<<< In File Menu >>>>
- ;-----------------------------------------------------------------------------
- InFileMenu
- CMP.W #QuitItem,D6
- BEQ Get_Outta_Here
- BRA MainLoop
-
-
-
- ;-----------------------------------------------------------------------------
- ; <<<< Click in edit menu >>>>
- ;-----------------------------------------------------------------------------
- InEditMenu
- sub.w #1,D6 ;subtract 1 to correspond to below info
- CLR.W -(SP)
- MOVE.W D6,-(SP) ;Undo=0,cut=2,copy=3,etc...
- _SysEdit
- MOVE.W (SP)+,D0
- BRA MenuDone
-
-
-
- ;-----------------------------------------------------------------------------
- ; <<<< Click in System Window >>>>
- ;-----------------------------------------------------------------------------
- SysWindow
- bsr saveresfileandport
- PEA eventRecord(A5)
- MOVE.L TheWindow(A5),-(SP)
- _SystemClick
- bsr restoreresfileandport
- BRA MainLoop
-
-
-
- ;-----------------------------------------------------------------------------
- ;-----------------------------------------------------------------------------
- ; <<<< MISC. ROUTINES >>>>
- ;-----------------------------------------------------------------------------
- ;-----------------------------------------------------------------------------
-
-
- ;-----------------------------------------------------------------------------
- ; <<<< save & restore current port & res file >>>>
- ;-----------------------------------------------------------------------------
- SaveResFileandPort
- clr -(sp)
- _CurResFile
- move (sp)+,AResFile(A5)
- pea TheCurPort(A5)
- _GetPort
- rts
-
- RestoreResFileandPort
- move AResFile(A5),-(sp)
- _UseResFile
- move.l TheCurPort(A5),-(SP)
- _SetPort
- rts
-
-
- ;-----------------------------------------------------------------------------
- ; <<<<< Globals >>>>>
- ;-----------------------------------------------------------------------------
-
- TheWindow ds.l 1
- TheCurPort ds.l 1
- AResFile ds 1
- thisresfile ds 1
-
- MenuOneHandle DS.L 1
- MenuTwoHandle DS.L 1
- MenuThreeHandle DS.L 1
-
- eventRecord DS.B 20 ; Event Record
-
- AccName DS.B 32 ; Desk Acc. Name
-
- END
-